<?php
/**
 * Created by JetBrains PhpStorm.
 * User: 蒋文书
 * Date: 14-12-27
 * Time: 下午11:27
 * To change this template use File | Settings | File Templates.
 */

namespace Admin\Controller;
use Think\Controller;


class CommonController extends Controller{

   public function _initialize(){

        /* 读取数据库中的配置 */
        $this->assign('userId', $_SESSION['uid']);
        $this->assign('langSet', LANG_SET);
        $config =   D('Config')->lists();
        C($config); //添加配置
        
        if(!C('RBAC_SUPERADMIN') && C('ADMIN_ALLOW_IP')){
            // 检查IP地址访问
            if(!in_array(get_client_ip(),explode(',',C('ADMIN_ALLOW_IP')))){
                $this->error('403:禁止访问');
            }
        }

        $notAuth=in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE'))) || 
        in_array(CONTROLLER_NAME, explode(',', C('NOT_AUTH_ACTION')));
        if(C('USER_AUTH_ON') && !$notAuth){
            $RBAC = new \Org\Util\Rbac();
             if(!$RBAC::AccessDecision()){
                if(!$_SESSION[C('USER_AUTH_KEY')]){
                    $this->redirect('Admin/Public/Index'); 
                }
                $this->error("您没有操作权限");
            }
        }
   }

}